namespace QMVnSoft.Controls
{
    using QMVnSoft;
    using QMVnSoft.Invoices;
    using QMVnSoft.Properties;
    using QMVnSoft.DAL;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class FormEditor : FormControl
    {
        private ToolStripButton btnAdd;
        private ToolStripButton btnClose;
        private ToolStripButton btnCopy;
        private ToolStripButton btnDesign;
        private ToolStripDropDownButton btnFunctions;
        private ToolStripButton btnPreview;
        private ToolStripButton btnPrint;
        private ToolStripButton btnSave;
        private IContainer components;
        private GBoxControl gBoxControl1;
        private GBoxControl gBoxControl2;
        private bool ib_CheckAccepted;
        private bool ib_CheckDrillDown;
        private bool ib_CheckNewRow;
        private bool ib_ExchangeType;
        private bool ib_MasterOrDetail;
        private decimal ii_ExchangeRateOfBook;
        private string is_SavedDetailOrder;
        private string is_SavedMasterOrder;
        private string is_TranCurrencyCode;
        private LabelControl labelControl5;
        private LabelControl lblNgay_Ct;
        private LabelControl lblNgay_Ps;
        private LabelControl lblNotice;
        public LabelControl lblPhan_Loai;
        private LabelControl lblSo_Ct;
        private GridControl oDetailGridBrowser;
        private GridControl oDetailSubBrowser;
        private AppInvoiceLib oAppInvoiceLib;
        private AppPrintInvoiceLib oAppPrintLib;
        private TextSearch oInputTypeTextBox;
        private DataSet oLocalDetailDataSet;
        private DataRow oLocalDetailRow;
        private FormLister oLocalFormLister;
        private DataRow oLocalMasterRow;
        private DataRow oLocalParentMasterRow;
        private PictureBox pictureBox1;
        private ToolStripSeparator tbrSep01;
        private ToolStripSeparator tbrSep02;
        private ToolStripSeparator tbrSep03;
        private ToolStripSeparator tbrSep04;
        private ToolStripSeparator tbtSep05;
        private ToolStrip Toolbars;
        private TextControl txtLocked;
        public TextSearch txtMa_Loai1;
        public TextSearch txtMa_Loai2;
        public TextSearch txtMa_Loai3;
        public TextDate txtNgay_Ct;
        public TextDate txtNgay_Ps;
        private TextControl txtPosted;
        public TextControl txtSo_Ct;
        private TextControl txtUserName;

        public FormEditor()
        {
            this.is_TranCurrencyCode = AppInstance.DefaultCurrency;
            this.ii_ExchangeRateOfBook = 1M;
            this.ib_ExchangeType = true;
            this.is_SavedMasterOrder = "";
            this.is_SavedDetailOrder = "";
            this.ib_MasterOrDetail = true;
            this.InitializeComponent();
        }

        public FormEditor(AppInvoiceLib po_AppInvoiceLib)
        {
            this.is_TranCurrencyCode = AppInstance.DefaultCurrency;
            this.ii_ExchangeRateOfBook = 1M;
            this.ib_ExchangeType = true;
            this.is_SavedMasterOrder = "";
            this.is_SavedDetailOrder = "";
            this.ib_MasterOrDetail = true;
            this.InitializeComponent();
            this.AppInvoiceParameters = po_AppInvoiceLib;
        }

        public FormEditor(string ps_InvoiceCode, string ps_MasterInvoiceOrder)
        {
            this.is_TranCurrencyCode = AppInstance.DefaultCurrency;
            this.ii_ExchangeRateOfBook = 1M;
            this.ib_ExchangeType = true;
            this.is_SavedMasterOrder = "";
            this.is_SavedDetailOrder = "";
            this.ib_MasterOrDetail = true;
            this.InitializeComponent();
            this.CheckDrillDown = true;
            this.CheckNewRow = false;
            this.CheckAccepted = false;
            this.SavedMasterOrder = ps_MasterInvoiceOrder;
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (!this.AppInvoiceParameters.AllowAddInvoice)
            {
                MessageBox.Show("Không có quyền thêm chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                if (this.btnSave.Enabled)
                {
                    this.OnSave();
                }
                this.OnAdd();
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnCopy_Click(object sender, EventArgs e)
        {
            if (!this.AppInvoiceParameters.AllowAddInvoice)
            {
                MessageBox.Show("Không có quyền thêm chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                if (this.btnSave.Enabled)
                {
                    this.OnSave();
                }
                this.OnCopy();
            }
        }

        private void btnDesign_Click(object sender, EventArgs e)
        {
            this.OnDesign();
        }

        private void btnPreview_Click(object sender, EventArgs e)
        {
            if (!this.AppInvoiceParameters.AllowViewInvoice)
            {
                MessageBox.Show("Không có quyền xem, in chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                this.OnPrint(false);
            }
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (!this.AppInvoiceParameters.AllowViewInvoice)
            {
                MessageBox.Show("Không có quyền xem, in chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
            else
            {
                this.OnPrint(true);
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.OnSave())
            {
                base.Close();
            }
        }

        private void Detail_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            if (((this.DetailGridBrowser.CurrentRow != null) && (this.DetailGridBrowser.CurrentRow.DataBoundItem != null)) && (this.txtNgay_Ct.Value != DBNull.Value))
            {
                DataRow row = ((DataRowView) this.DetailGridBrowser.CurrentRow.DataBoundItem).Row;
                this.SavedDetailOrder = row[this.AppInvoiceParameters.DetailKeyField].ToString();
            }
        }

        protected override void Dispose(bool disposing)
        {
            if ((this.LocalFormLister != null) && !this.CheckAccepted)
            {
                if (this.CheckNewRow && !this.CheckAccepted)
                {
                    this.CheckNewRow = false;
                    this.CheckAccepted = true;
                    this.LocalFormLister.OnShowMaster();
                }
                else
                {
                    this.LocalMasterRow.RejectChanges();
                    this.LocalDetailTable.RejectChanges();
                }
            }
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormEditor));
            this.lblPhan_Loai = new QMVnSoft.Controls.LabelControl();
            this.txtMa_Loai1 = new QMVnSoft.Controls.TextSearch();
            this.txtMa_Loai2 = new QMVnSoft.Controls.TextSearch();
            this.txtMa_Loai3 = new QMVnSoft.Controls.TextSearch();
            this.Toolbars = new System.Windows.Forms.ToolStrip();
            this.btnFunctions = new System.Windows.Forms.ToolStripDropDownButton();
            this.tbrSep01 = new System.Windows.Forms.ToolStripSeparator();
            this.btnAdd = new System.Windows.Forms.ToolStripButton();
            this.btnCopy = new System.Windows.Forms.ToolStripButton();
            this.tbrSep02 = new System.Windows.Forms.ToolStripSeparator();
            this.btnSave = new System.Windows.Forms.ToolStripButton();
            this.tbrSep03 = new System.Windows.Forms.ToolStripSeparator();
            this.btnPreview = new System.Windows.Forms.ToolStripButton();
            this.btnPrint = new System.Windows.Forms.ToolStripButton();
            this.tbrSep04 = new System.Windows.Forms.ToolStripSeparator();
            this.btnDesign = new System.Windows.Forms.ToolStripButton();
            this.tbtSep05 = new System.Windows.Forms.ToolStripSeparator();
            this.btnClose = new System.Windows.Forms.ToolStripButton();
            this.txtUserName = new QMVnSoft.Controls.TextControl();
            this.txtPosted = new QMVnSoft.Controls.TextControl();
            this.txtLocked = new QMVnSoft.Controls.TextControl();
            this.txtSo_Ct = new QMVnSoft.Controls.TextControl();
            this.lblNgay_Ps = new QMVnSoft.Controls.LabelControl();
            this.txtNgay_Ps = new QMVnSoft.Controls.TextDate();
            this.lblNgay_Ct = new QMVnSoft.Controls.LabelControl();
            this.txtNgay_Ct = new QMVnSoft.Controls.TextDate();
            this.lblSo_Ct = new QMVnSoft.Controls.LabelControl();
            this.labelControl5 = new QMVnSoft.Controls.LabelControl();
            this.lblNotice = new QMVnSoft.Controls.LabelControl();
            this.gBoxControl1 = new QMVnSoft.Controls.GBoxControl();
            this.gBoxControl2 = new QMVnSoft.Controls.GBoxControl();
            this.pictureBox1 = new System.Windows.Forms.PictureBox();
            this.Toolbars.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // lblPhan_Loai
            // 
            this.lblPhan_Loai.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.lblPhan_Loai.AutoSize = true;
            this.lblPhan_Loai.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblPhan_Loai.Location = new System.Drawing.Point(12, 490);
            this.lblPhan_Loai.Name = "lblPhan_Loai";
            this.lblPhan_Loai.Size = new System.Drawing.Size(50, 14);
            this.lblPhan_Loai.TabIndex = 1;
            this.lblPhan_Loai.Text = "Phân loại";
            // 
            // txtMa_Loai1
            // 
            this.txtMa_Loai1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.txtMa_Loai1.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_Loai1.CheckTextSearched = false;
            this.txtMa_Loai1.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtMa_Loai1.EmptyIsValid = true;
            this.txtMa_Loai1.FirstFilter = "Type = \'CT1\'";
            this.txtMa_Loai1.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_Loai1.FoundIsValid = true;
            this.txtMa_Loai1.Location = new System.Drawing.Point(99, 487);
            this.txtMa_Loai1.MaxLength = 32;
            this.txtMa_Loai1.Name = "txtMa_Loai1";
            this.txtMa_Loai1.OldValue = null;
            this.txtMa_Loai1.Size = new System.Drawing.Size(227, 20);
            this.txtMa_Loai1.TabIndex = 4;
            this.txtMa_Loai1.TableName = "DMLOAI";
            this.txtMa_Loai1.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_Loai1.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_Loai1.Value = ((object)(resources.GetObject("txtMa_Loai1.Value")));
            // 
            // txtMa_Loai2
            // 
            this.txtMa_Loai2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.txtMa_Loai2.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_Loai2.CheckTextSearched = false;
            this.txtMa_Loai2.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtMa_Loai2.EmptyIsValid = true;
            this.txtMa_Loai2.FirstFilter = "Type = \'CT2\'";
            this.txtMa_Loai2.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_Loai2.FoundIsValid = true;
            this.txtMa_Loai2.Location = new System.Drawing.Point(327, 487);
            this.txtMa_Loai2.MaxLength = 32;
            this.txtMa_Loai2.Name = "txtMa_Loai2";
            this.txtMa_Loai2.OldValue = null;
            this.txtMa_Loai2.Size = new System.Drawing.Size(227, 20);
            this.txtMa_Loai2.TabIndex = 5;
            this.txtMa_Loai2.TableName = "DMLOAI";
            this.txtMa_Loai2.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_Loai2.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_Loai2.Value = ((object)(resources.GetObject("txtMa_Loai2.Value")));
            // 
            // txtMa_Loai3
            // 
            this.txtMa_Loai3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.txtMa_Loai3.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtMa_Loai3.CheckTextSearched = false;
            this.txtMa_Loai3.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtMa_Loai3.EmptyIsValid = true;
            this.txtMa_Loai3.FirstFilter = "Type = \'CT3\'";
            this.txtMa_Loai3.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtMa_Loai3.FoundIsValid = true;
            this.txtMa_Loai3.Location = new System.Drawing.Point(555, 487);
            this.txtMa_Loai3.MaxLength = 32;
            this.txtMa_Loai3.Name = "txtMa_Loai3";
            this.txtMa_Loai3.OldValue = null;
            this.txtMa_Loai3.Size = new System.Drawing.Size(227, 20);
            this.txtMa_Loai3.TabIndex = 6;
            this.txtMa_Loai3.TableName = "DMLOAI";
            this.txtMa_Loai3.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.ItemCode;
            this.txtMa_Loai3.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.All;
            this.txtMa_Loai3.Value = ((object)(resources.GetObject("txtMa_Loai3.Value")));
            // 
            // Toolbars
            // 
            this.Toolbars.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.btnFunctions,
            this.tbrSep01,
            this.btnAdd,
            this.btnCopy,
            this.tbrSep02,
            this.btnSave,
            this.tbrSep03,
            this.btnPreview,
            this.btnPrint,
            this.tbrSep04,
            this.btnDesign,
            this.tbtSep05,
            this.btnClose});
            this.Toolbars.Location = new System.Drawing.Point(0, 0);
            this.Toolbars.Name = "Toolbars";
            this.Toolbars.Size = new System.Drawing.Size(794, 25);
            this.Toolbars.TabIndex = 0;
            this.Toolbars.Text = "Toolbars";
            // 
            // btnFunctions
            // 
            this.btnFunctions.Image = ((System.Drawing.Image)(resources.GetObject("btnFunctions.Image")));
            this.btnFunctions.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnFunctions.Name = "btnFunctions";
            this.btnFunctions.Size = new System.Drawing.Size(94, 22);
            this.btnFunctions.Text = "Chức năng";
            this.btnFunctions.ToolTipText = "Chức năng";
            this.btnFunctions.Visible = false;
            // 
            // tbrSep01
            // 
            this.tbrSep01.Name = "tbrSep01";
            this.tbrSep01.Size = new System.Drawing.Size(6, 25);
            this.tbrSep01.Visible = false;
            // 
            // btnAdd
            // 
            this.btnAdd.Image = global::QMVnSoft.Properties.Resources.BALANCE1;
            this.btnAdd.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnAdd.Name = "btnAdd";
            this.btnAdd.Size = new System.Drawing.Size(58, 22);
            this.btnAdd.Text = "Thêm";
            this.btnAdd.ToolTipText = "Thêm mới (F2)";
            this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
            // 
            // btnCopy
            // 
            this.btnCopy.Image = global::QMVnSoft.Properties.Resources.COPY1;
            this.btnCopy.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnCopy.Name = "btnCopy";
            this.btnCopy.Size = new System.Drawing.Size(75, 22);
            this.btnCopy.Text = "Sao chép";
            this.btnCopy.ToolTipText = "Sao chép chứng từ (Ctrl+F2)";
            this.btnCopy.Click += new System.EventHandler(this.btnCopy_Click);
            // 
            // tbrSep02
            // 
            this.tbrSep02.Name = "tbrSep02";
            this.tbrSep02.Size = new System.Drawing.Size(6, 25);
            // 
            // btnSave
            // 
            this.btnSave.Image = global::QMVnSoft.Properties.Resources.SAVE1;
            this.btnSave.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnSave.Name = "btnSave";
            this.btnSave.Size = new System.Drawing.Size(47, 22);
            this.btnSave.Text = "Lưu";
            this.btnSave.ToolTipText = "Ghi lại và Thoát (Ctrl+Enter)";
            this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
            // 
            // tbrSep03
            // 
            this.tbrSep03.Name = "tbrSep03";
            this.tbrSep03.Size = new System.Drawing.Size(6, 25);
            this.tbrSep03.Visible = false;
            // 
            // btnPreview
            // 
            this.btnPreview.Enabled = false;
            this.btnPreview.Image = global::QMVnSoft.Properties.Resources.PREVIEW1;
            this.btnPreview.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnPreview.Name = "btnPreview";
            this.btnPreview.Size = new System.Drawing.Size(51, 22);
            this.btnPreview.Text = "Xem";
            this.btnPreview.ToolTipText = "Xem trước khi in (Ctrl+F7)";
            this.btnPreview.Visible = false;
            this.btnPreview.Click += new System.EventHandler(this.btnPreview_Click);
            // 
            // btnPrint
            // 
            this.btnPrint.Enabled = false;
            this.btnPrint.Image = global::QMVnSoft.Properties.Resources.PRINT1;
            this.btnPrint.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnPrint.Name = "btnPrint";
            this.btnPrint.Size = new System.Drawing.Size(37, 22);
            this.btnPrint.Text = "In";
            this.btnPrint.ToolTipText = "In chứng từ (F7)";
            this.btnPrint.Visible = false;
            this.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
            // 
            // tbrSep04
            // 
            this.tbrSep04.Name = "tbrSep04";
            this.tbrSep04.Size = new System.Drawing.Size(6, 25);
            this.tbrSep04.Visible = false;
            // 
            // btnDesign
            // 
            this.btnDesign.Enabled = false;
            this.btnDesign.Image = global::QMVnSoft.Properties.Resources.DESIGN1;
            this.btnDesign.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnDesign.Name = "btnDesign";
            this.btnDesign.Size = new System.Drawing.Size(46, 22);
            this.btnDesign.Text = "Sửa";
            this.btnDesign.ToolTipText = "Sửa mẫu báo cáo (Ctrl+F3)";
            this.btnDesign.Visible = false;
            this.btnDesign.Click += new System.EventHandler(this.btnDesign_Click);
            // 
            // tbtSep05
            // 
            this.tbtSep05.Name = "tbtSep05";
            this.tbtSep05.Size = new System.Drawing.Size(6, 25);
            this.tbtSep05.Visible = false;
            // 
            // btnClose
            // 
            this.btnClose.Image = global::QMVnSoft.Properties.Resources.CLOSE;
            this.btnClose.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnClose.Name = "btnClose";
            this.btnClose.Size = new System.Drawing.Size(58, 22);
            this.btnClose.Text = "Thoát";
            this.btnClose.ToolTipText = "Thoát (Esc)";
            this.btnClose.Visible = false;
            this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
            // 
            // txtUserName
            // 
            this.txtUserName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.txtUserName.BackColor = System.Drawing.Color.Aquamarine;
            this.txtUserName.CheckTextSearched = false;
            this.txtUserName.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtUserName.Enabled = false;
            this.txtUserName.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtUserName.Location = new System.Drawing.Point(724, 28);
            this.txtUserName.Name = "txtUserName";
            this.txtUserName.OldValue = null;
            this.txtUserName.Size = new System.Drawing.Size(58, 20);
            this.txtUserName.TabIndex = 1;
            this.txtUserName.Text = "ADMIN";
            this.txtUserName.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.txtUserName.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.None;
            this.txtUserName.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.Right;
            this.txtUserName.Value = "ADMIN";
            // 
            // txtPosted
            // 
            this.txtPosted.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.txtPosted.BackColor = System.Drawing.Color.Aquamarine;
            this.txtPosted.CheckTextSearched = false;
            this.txtPosted.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtPosted.Enabled = false;
            this.txtPosted.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtPosted.Location = new System.Drawing.Point(667, 28);
            this.txtPosted.Name = "txtPosted";
            this.txtPosted.OldValue = null;
            this.txtPosted.Size = new System.Drawing.Size(58, 20);
            this.txtPosted.TabIndex = 1;
            this.txtPosted.Text = "Sổ cái";
            this.txtPosted.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.txtPosted.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.None;
            this.txtPosted.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.Right;
            this.txtPosted.Value = "Sổ cái";
            // 
            // txtLocked
            // 
            this.txtLocked.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.txtLocked.BackColor = System.Drawing.Color.Aquamarine;
            this.txtLocked.CheckTextSearched = false;
            this.txtLocked.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtLocked.Enabled = false;
            this.txtLocked.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtLocked.Location = new System.Drawing.Point(610, 28);
            this.txtLocked.Name = "txtLocked";
            this.txtLocked.OldValue = null;
            this.txtLocked.Size = new System.Drawing.Size(58, 20);
            this.txtLocked.TabIndex = 1;
            this.txtLocked.Text = "Khóa";
            this.txtLocked.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
            this.txtLocked.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.None;
            this.txtLocked.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.Right;
            this.txtLocked.Value = "Khóa";
            // 
            // txtSo_Ct
            // 
            this.txtSo_Ct.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.txtSo_Ct.CheckTextSearched = false;
            this.txtSo_Ct.DisabledForeColor = System.Drawing.Color.Blue;
            this.txtSo_Ct.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtSo_Ct.Location = new System.Drawing.Point(236, 53);
            this.txtSo_Ct.Name = "txtSo_Ct";
            this.txtSo_Ct.OldValue = null;
            this.txtSo_Ct.Size = new System.Drawing.Size(90, 20);
            this.txtSo_Ct.TabIndex = 3;
            this.txtSo_Ct.UserTextLength  = QMVnSoft.AppInstance.TextControlLength.None;
            this.txtSo_Ct.UserTrimMode  = QMVnSoft.AppInstance.TextControlTrimMode.Right;
            this.txtSo_Ct.Value = ((object)(resources.GetObject("txtSo_Ct.Value")));
            // 
            // lblNgay_Ps
            // 
            this.lblNgay_Ps.AutoSize = true;
            this.lblNgay_Ps.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblNgay_Ps.Location = new System.Drawing.Point(12, 31);
            this.lblNgay_Ps.Name = "lblNgay_Ps";
            this.lblNgay_Ps.Size = new System.Drawing.Size(78, 14);
            this.lblNgay_Ps.TabIndex = 5;
            this.lblNgay_Ps.Text = "Ngày lập phiếu";
            // 
            // txtNgay_Ps
            // 
            this.txtNgay_Ps.DateTimeFormat  = QMVnSoft.Controls.TextDate.DateTimeFormatType.Date;
            this.txtNgay_Ps.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtNgay_Ps.InsertKeyMode = System.Windows.Forms.InsertKeyMode.Overwrite;
            this.txtNgay_Ps.Location = new System.Drawing.Point(99, 28);
            this.txtNgay_Ps.Mask = "00/00/0000";
            this.txtNgay_Ps.Name = "txtNgay_Ps";
            this.txtNgay_Ps.OldValue = null;
            this.txtNgay_Ps.Size = new System.Drawing.Size(79, 20);
            this.txtNgay_Ps.TabIndex = 1;
            this.txtNgay_Ps.Value = ((object)(resources.GetObject("txtNgay_Ps.Value")));
            // 
            // lblNgay_Ct
            // 
            this.lblNgay_Ct.AutoSize = true;
            this.lblNgay_Ct.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblNgay_Ct.Location = new System.Drawing.Point(12, 56);
            this.lblNgay_Ct.Name = "lblNgay_Ct";
            this.lblNgay_Ct.Size = new System.Drawing.Size(79, 14);
            this.lblNgay_Ct.TabIndex = 5;
            this.lblNgay_Ct.Text = "Ngày chứng từ";
            // 
            // txtNgay_Ct
            // 
            this.txtNgay_Ct.DateTimeFormat  = QMVnSoft.Controls.TextDate.DateTimeFormatType.Date;
            this.txtNgay_Ct.Font = new System.Drawing.Font("Arial", 8.25F);
            this.txtNgay_Ct.InsertKeyMode = System.Windows.Forms.InsertKeyMode.Overwrite;
            this.txtNgay_Ct.Location = new System.Drawing.Point(99, 53);
            this.txtNgay_Ct.Mask = "00/00/0000";
            this.txtNgay_Ct.Name = "txtNgay_Ct";
            this.txtNgay_Ct.OldValue = null;
            this.txtNgay_Ct.Size = new System.Drawing.Size(79, 20);
            this.txtNgay_Ct.TabIndex = 2;
            this.txtNgay_Ct.Value = ((object)(resources.GetObject("txtNgay_Ct.Value")));
            // 
            // lblSo_Ct
            // 
            this.lblSo_Ct.AutoSize = true;
            this.lblSo_Ct.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblSo_Ct.Location = new System.Drawing.Point(210, 56);
            this.lblSo_Ct.Name = "lblSo_Ct";
            this.lblSo_Ct.Size = new System.Drawing.Size(20, 14);
            this.lblSo_Ct.TabIndex = 5;
            this.lblSo_Ct.Text = "Số";
            // 
            // labelControl5
            // 
            this.labelControl5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.labelControl5.BackColor = System.Drawing.Color.White;
            this.labelControl5.Font = new System.Drawing.Font("Arial", 8.25F);
            this.labelControl5.ForeColor = System.Drawing.Color.Blue;
            this.labelControl5.Location = new System.Drawing.Point(1, 511);
            this.labelControl5.Name = "labelControl5";
            this.labelControl5.Size = new System.Drawing.Size(792, 20);
            this.labelControl5.TabIndex = 1;
            // 
            // lblNotice
            // 
            this.lblNotice.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.lblNotice.BackColor = System.Drawing.Color.White;
            this.lblNotice.Font = new System.Drawing.Font("Arial", 8.25F);
            this.lblNotice.ForeColor = System.Drawing.Color.Blue;
            this.lblNotice.Location = new System.Drawing.Point(26, 514);
            this.lblNotice.Name = "lblNotice";
            this.lblNotice.Size = new System.Drawing.Size(762, 14);
            this.lblNotice.TabIndex = 1;
            // 
            // gBoxControl1
            // 
            this.gBoxControl1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.gBoxControl1.Font = new System.Drawing.Font("Arial", 8.25F);
            this.gBoxControl1.Location = new System.Drawing.Point(-3, 504);
            this.gBoxControl1.Name = "gBoxControl1";
            this.gBoxControl1.Size = new System.Drawing.Size(799, 7);
            this.gBoxControl1.TabIndex = 8;
            this.gBoxControl1.TabStop = false;
            // 
            // gBoxControl2
            // 
            this.gBoxControl2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.gBoxControl2.Font = new System.Drawing.Font("Arial", 8.25F);
            this.gBoxControl2.Location = new System.Drawing.Point(-5, 45);
            this.gBoxControl2.Name = "gBoxControl2";
            this.gBoxControl2.Size = new System.Drawing.Size(804, 7);
            this.gBoxControl2.TabIndex = 9;
            this.gBoxControl2.TabStop = false;
            // 
            // pictureBox1
            // 
            this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.pictureBox1.Image = global::QMVnSoft.Properties.Resources.INFO;
            this.pictureBox1.Location = new System.Drawing.Point(10, 516);
            this.pictureBox1.Name = "pictureBox1";
            this.pictureBox1.Size = new System.Drawing.Size(11, 11);
            this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
            this.pictureBox1.TabIndex = 7;
            this.pictureBox1.TabStop = false;
            // 
            // FormEditor
            // 
            this.ClientSize = new System.Drawing.Size(794, 539);
            this.Controls.Add(this.Toolbars);
            this.Controls.Add(this.txtMa_Loai3);
            this.Controls.Add(this.txtMa_Loai2);
            this.Controls.Add(this.txtMa_Loai1);
            this.Controls.Add(this.gBoxControl1);
            this.Controls.Add(this.pictureBox1);
            this.Controls.Add(this.txtNgay_Ct);
            this.Controls.Add(this.txtNgay_Ps);
            this.Controls.Add(this.lblSo_Ct);
            this.Controls.Add(this.lblNgay_Ct);
            this.Controls.Add(this.lblNgay_Ps);
            this.Controls.Add(this.txtPosted);
            this.Controls.Add(this.txtLocked);
            this.Controls.Add(this.txtSo_Ct);
            this.Controls.Add(this.txtUserName);
            this.Controls.Add(this.lblNotice);
            this.Controls.Add(this.labelControl5);
            this.Controls.Add(this.lblPhan_Loai);
            this.Controls.Add(this.gBoxControl2);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MinimumSize = new System.Drawing.Size(802, 566);
            this.Name = "FormEditor";
            this.Toolbars.ResumeLayout(false);
            this.Toolbars.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        internal void MakeDetailDataRow()
        {
            this.LocalDetailTable.Rows.Add(this.MakeDetailRow());
        }

        internal DataRow MakeDetailRow()
        {
            DataRow row = this.LocalDetailTable.NewRow();
            row[this.AppInvoiceParameters.DetailKeyField] = AppDataAccess.Cong_So_Tt(AppInstance.Subsidiary);
            if (this.LocalDetailRow != null)
            {
                foreach (DataColumn column in this.LocalDetailTable.Columns)
                {
                    if (this.AppInvoiceParameters.DetailFieldsOverride.Contains("," + column.ColumnName.ToUpper() + ","))
                    {
                        row[column.ColumnName] = this.LocalDetailRow[column.ColumnName];
                    }
                }
            }
            return row;
        }

        internal void MakeDetailTable()
        {
            DataRow row = this.MakeDetailRow();
            this.LocalDetailTable.Rows.Clear();
            this.LocalDetailTable.Rows.Add(row);
        }

        internal DataRow MakeMasterRow()
        {
            DataRow row = this.LocalMasterRow.Table.NewRow();
            this.SavedMasterOrder = AppDataAccess.Cong_So_Tt(AppInstance.Subsidiary);
            row["Posted"] = this.AppInvoiceParameters.DefaultPostStatus;
            row["Locked"] = this.AppInvoiceParameters.DefaultLockStatus;
            row["UserName"] = AppInstance.UserName;
            row["Ma_Ct"] = this.InvoiceCode;
            row[this.AppInvoiceParameters.MasterKeyField] = this.SavedMasterOrder;
            row["Ngay_Ps"] = ((this.LocalMasterRow == null) || (this.LocalMasterRow["Ngay_Ps"] == DBNull.Value)) ? DateTime.Today : this.LocalMasterRow["Ngay_Ps"];
            row["Ngay_Ct"] = ((this.LocalMasterRow == null) || (this.LocalMasterRow["Ngay_Ct"] == DBNull.Value)) ? DateTime.Today : this.LocalMasterRow["Ngay_Ct"];
            if (this.LocalMasterRow != null)
            {
                foreach (DataColumn column in this.LocalMasterRow.Table.Columns)
                {
                    if (this.AppInvoiceParameters.MasterFieldsOverride.Contains("," + column.ColumnName.ToUpper() + ","))
                    {
                        row[column.ColumnName] = this.LocalMasterRow[column.ColumnName];
                    }
                }
            }
            if (this.AppInvoiceParameters.FreeFields > 0)
            {
                row["Ma_Loai1"] = this.AppInvoiceParameters.FirstFreeCode;
                row["Ma_Loai2"] = this.AppInvoiceParameters.SecondFreeCode;
                row["Ma_Loai3"] = this.AppInvoiceParameters.ThirdFreeCode;
            }
            this.LocalMasterRow.Table.Rows.Clear();
            this.LocalMasterRow.Table.Rows.Add(row);
            return row;
        }

        internal virtual void OnAdd()
        {
            this.CheckNewRow = true;
            this.CheckAccepted = false;
            this.OnShow();
            this.txtNgay_Ps.Focus();
        }

        internal virtual void OnCopy()
        {
            this.CheckNewRow = true;
            this.CheckAccepted = false;
            this.SavedMasterOrder = AppDataAccess.Cong_So_Tt(AppInstance.Subsidiary);
            this.LocalMasterRow["Posted"] = this.AppInvoiceParameters.DefaultPostStatus;
            this.LocalMasterRow["Locked"] = this.AppInvoiceParameters.DefaultLockStatus;
            this.LocalMasterRow["UserName"] = AppInstance.UserName;
            this.LocalMasterRow[this.AppInvoiceParameters.MasterKeyField] = this.SavedMasterOrder;
            foreach (DataRow row in this.LocalDetailTable.Rows)
            {
                if (row.RowState != DataRowState.Deleted)
                {
                    row[this.AppInvoiceParameters.DetailKeyField] = AppDataAccess.Cong_So_Tt(AppInstance.Subsidiary);
                }
            }
            this.SetPostedText();
        }

        protected void OnDesign()
        {
            this.AppPrintLib.OnDesign(this.AppInvoiceParameters);
        }

        private void OnPrint(bool pb_Printed)
        {
            if (this.AppInvoiceParameters.HistoryType == "K")
            {
                this.AppPrintLib.OnCTKTPrint(pb_Printed, this.AppInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.AppInvoiceParameters.HistoryType == "M")
            {
                this.AppPrintLib.OnCTMHPrint(pb_Printed, this.AppInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.AppInvoiceParameters.HistoryType == "B")
            {
                this.AppPrintLib.OnCTBHPrint(pb_Printed, this.AppInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.AppInvoiceParameters.HistoryType == "Q")
            {
                this.AppPrintLib.OnCTBGPrint(pb_Printed, this.AppInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.AppInvoiceParameters.HistoryType == "D")
            {
                this.AppPrintLib.OnCTDHPrint(pb_Printed, this.AppInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.AppInvoiceParameters.HistoryType == "N")
            {
                this.AppPrintLib.OnCTNXPrint(pb_Printed, this.AppInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.AppInvoiceParameters.HistoryType == "Y")
            {
                this.AppPrintLib.OnCTYCMPrint(pb_Printed, this.AppInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.AppInvoiceParameters.HistoryType == "W")
            {
                this.AppPrintLib.OnCTKHOPrint(pb_Printed, this.AppInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.AppInvoiceParameters.HistoryType == "P")
            {
                this.AppPrintLib.OnCTTPPrint(pb_Printed, this.AppInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.AppInvoiceParameters.HistoryType == "S")
            {
                this.AppPrintLib.OnCTSXPrint(pb_Printed, this.AppInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.AppInvoiceParameters.HistoryType == "O")
            {
                this.AppPrintLib.OnCTNBPrint(pb_Printed, this.AppInvoiceParameters, this.LocalMasterRow, this.LocalDetailTable);
            }
            else if (this.AppInvoiceParameters.HistoryType == "T")
            {
                this.AppPrintLib.OnCTVATPrint(pb_Printed, this.AppInvoiceParameters, this.LocalMasterRow);
            }
        }

        internal virtual void OnResetControls()
        {
            if (this.AppInvoiceParameters.FreeFields <= 0)
            {
                this.lblPhan_Loai.Visible = false;
                this.txtMa_Loai1.Visible = false;
                this.txtMa_Loai2.Visible = false;
                this.txtMa_Loai3.Visible = false;
            }
            this.DetailGridBrowser.SetColumnWidths();
            if (this.DetailSubBrowser != null)
            {
                this.DetailSubBrowser.SetColumnWidths();
            }
        }

        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);
            if (((this.txtMa_Loai1 != null) && (this.AppInvoiceParameters != null)) && (this.AppInvoiceParameters.FreeFields > 0))
            {
                int num = base.ClientSize.Width - 0x71;
                this.txtMa_Loai1.Width = num / 3;
                this.txtMa_Loai2.Left = (this.txtMa_Loai1.Left + this.txtMa_Loai1.Width) + 1;
                this.txtMa_Loai2.Width = num / 3;
                this.txtMa_Loai3.Left = (this.txtMa_Loai2.Left + this.txtMa_Loai2.Width) + 1;
                this.txtMa_Loai3.Width = (num - this.txtMa_Loai1.Width) - this.txtMa_Loai2.Width;
            }
        }

        protected virtual bool OnSave()
        {
            if (this.LocalFormLister != null)
            {
                DataRow localParentMasterRow;
                if (this.CheckNewRow)
                {
                    localParentMasterRow = this.LocalParentMasterRow.Table.NewRow();
                    this.LocalParentMasterRow.Table.Rows.Add(localParentMasterRow);
                }
                else
                {
                    localParentMasterRow = this.LocalParentMasterRow;
                }
                foreach (DataColumn column in this.LocalParentMasterRow.Table.Columns)
                {
                    if (this.LocalMasterRow.Table.Columns.Contains(column.ColumnName))
                    {
                        localParentMasterRow[column.ColumnName] = this.LocalMasterRow[column.ColumnName];
                    }
                }
                localParentMasterRow.EndEdit();
                this.LocalParentMasterRow.Table.AcceptChanges();
                this.LocalFormLister.LocalMasterRow = this.LocalMasterRow;
                this.LocalFormLister.LocalDetailDataSet = this.LocalDetailDataSet;
                this.LocalFormLister.OnSetPosition(this.SavedMasterOrder);
                this.CheckAccepted = true;
            }
            return true;
        }

        internal virtual void OnShow()
        {
            if ((this.LocalMasterRow == null) || (this.LocalDetailTable == null))
            {
                this.OnShowMaster();
            }
            this.DetailGridBrowser.DataSource = new BindingSource(this.LocalDetailDataSet, this.LocalDetailTable.TableName);
            ((BindingSource) this.DetailGridBrowser.DataSource).Sort = this.DetailOrderString;
            if (this.DetailSubBrowser != null)
            {
                this.DetailSubBrowser.DataSource = new BindingSource(this.LocalDetailDataSet, this.LocalDetailTable.TableName);
                ((BindingSource) this.DetailSubBrowser.DataSource).Sort = this.DetailOrderString;
            }
            this.txtNgay_Ps.Value = this.LocalMasterRow["Ngay_Ps"];
            this.txtNgay_Ct.Value = this.LocalMasterRow["Ngay_Ct"];
            this.txtMa_Loai1.Value = this.LocalMasterRow["Ma_Loai1"];
            this.txtMa_Loai2.Value = this.LocalMasterRow["Ma_Loai2"];
            this.txtMa_Loai3.Value = this.LocalMasterRow["Ma_Loai3"];
            this.SetPostedText();
        }

        internal virtual void OnShowDetail()
        {
        }

        internal virtual void OnShowDetailNotice()
        {
            this.MasterOrDetail = false;
        }

        internal virtual void OnShowMaster()
        {
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (keyData)
            {
                case (Keys.Control | Keys.F2):
                    if (this.AppInvoiceParameters.AllowAddInvoice)
                    {
                        if (this.btnCopy.Enabled)
                        {
                            if (this.btnSave.Enabled)
                            {
                                this.OnSave();
                            }
                            this.OnCopy();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Không có quyền thêm chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    return true;

                case (Keys.Control | Keys.F3):
                    if (this.btnDesign.Enabled)
                    {
                        this.OnDesign();
                    }
                    return true;

                case (Keys.Control | Keys.F7):
                    if (!this.AppInvoiceParameters.AllowViewInvoice)
                    {
                        MessageBox.Show("Không có quyền xem, in chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    else if (this.btnPreview.Enabled)
                    {
                        this.OnPrint(false);
                    }
                    return true;

                case (Keys.Control | Keys.Return):
                    if (this.btnSave.Enabled && this.OnSave())
                    {
                        base.Close();
                    }
                    return true;

                case Keys.F2:
                    if (this.AppInvoiceParameters.AllowAddInvoice)
                    {
                        if (this.btnAdd.Enabled)
                        {
                            if (this.btnSave.Enabled)
                            {
                                this.OnSave();
                            }
                            this.OnAdd();
                        }
                        break;
                    }
                    MessageBox.Show("Không có quyền thêm chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    break;

                case Keys.F4:
                    if (this.DetailSubBrowser != null)
                    {
                        bool flag = false;
                        for (Control control = base.ActiveControl; (control != null) && (control != this); control = control.Parent)
                        {
                            if (control is GridDetail)
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (flag)
                        {
                            if (this.DetailGridBrowser.Visible)
                            {
                                this.DetailSubBrowser.Visible = true;
                                this.DetailSubBrowser.Focus();
                                this.DetailSubBrowser.CurrentCell = this.DetailSubBrowser[0, this.DetailGridBrowser.CurrentCell.RowIndex];
                                this.DetailGridBrowser.Visible = false;
                            }
                            else
                            {
                                this.DetailGridBrowser.Visible = true;
                                this.DetailGridBrowser.Focus();
                                this.DetailGridBrowser.CurrentCell = this.DetailGridBrowser[0, this.DetailSubBrowser.CurrentCell.RowIndex];
                                this.DetailSubBrowser.Visible = false;
                            }
                        }
                    }
                    return true;

                case Keys.F7:
                    if (!this.AppInvoiceParameters.AllowViewInvoice)
                    {
                        MessageBox.Show("Không có quyền xem, in chứng từ!", AppInstance.SoftwareName, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    else if (this.btnPrint.Enabled)
                    {
                        this.OnPrint(true);
                    }
                    return true;

                case Keys.Escape:
                    base.Close();
                    return true;

                default:
                    return base.ProcessCmdKey(ref msg, keyData);
            }
            return true;
        }

        private void SetPostedText()
        {
            if (this.LocalMasterRow.Table.Columns.Contains("Posted"))
            {
                switch (((int) this.LocalMasterRow["Posted"]))
                {
                    case 0:
                        this.txtPosted.Value = "Huỷ";
                        goto Label_006D;

                    case 1:
                        this.txtPosted.Value = "Sổ c\x00e1i";
                        goto Label_006D;
                }
                this.txtPosted.Value = "Duyệt";
            }
        Label_006D:
            if (this.LocalMasterRow.Table.Columns.Contains("Locked"))
            {
                this.txtLocked.Value = ((bool) this.LocalMasterRow["Locked"]) ? "Khóa" : "Mở";
            }
            this.txtUserName.Value = this.LocalMasterRow["UserName"];
            this.txtSo_Ct.Value = this.LocalMasterRow["So_Ct"];
        }

        [Category("Editor properties"), DefaultValue(false), Browsable(false), Description("Get or set action status: Accept or Cancel.")]
        public bool CheckAccepted
        {
            get
            {
                return this.ib_CheckAccepted;
            }
            set
            {
                this.ib_CheckAccepted = value;
            }
        }

        [Category("Editor properties"), Browsable(false), Description("Show editor form when viewing report."), DefaultValue(false)]
        public bool CheckDrillDown
        {
            get
            {
                return this.ib_CheckDrillDown;
            }
            set
            {
                this.ib_CheckDrillDown = value;
            }
        }

        [DefaultValue(false), Browsable(false), Category("Editor properties"), Description("Get or set action status: Add or Edit.")]
        public bool CheckNewRow
        {
            get
            {
                return this.ib_CheckNewRow;
            }
            set
            {
                this.ib_CheckNewRow = value;
            }
        }

        [Description("The datagridview to show detail invoice."), Category("Editor properties"), Browsable(false)]
        public GridControl DetailGridBrowser
        {
            get
            {
                return this.oDetailGridBrowser;
            }
            set
            {
                if (this.oDetailGridBrowser != value)
                {
                    this.oDetailGridBrowser = value;
                    this.oDetailGridBrowser.AutoGenerateColumns = false;
                    this.oDetailGridBrowser.CellEnter += new DataGridViewCellEventHandler(this.Detail_CellEnter);
                }
            }
        }

        [Description("The detail primary key field name."), Category("Editor properties"), DefaultValue("Stt0")]
        public string DetailKeyField
        {
            get
            {
                if (this.AppInvoiceParameters == null)
                {
                    return "";
                }
                return this.AppInvoiceParameters.DetailKeyField;
            }
            set
            {
                if (this.AppInvoiceParameters != null)
                {
                    this.AppInvoiceParameters.DetailKeyField = value;
                }
            }
        }

        [Description("The detail order string."), Category("Editor properties"), DefaultValue("Stt_Nv")]
        public string DetailOrderString
        {
            get
            {
                return this.AppInvoiceParameters.DetailOrderString;
            }
            set
            {
                if (this.AppInvoiceParameters != null)
                {
                    this.AppInvoiceParameters.DetailOrderString = value;
                }
            }
        }

        [Category("Editor properties"), Browsable(false), Description("The datagridview to show sub detail invoice.")]
        public GridControl DetailSubBrowser
        {
            get
            {
                return this.oDetailSubBrowser;
            }
            set
            {
                if (this.oDetailSubBrowser != value)
                {
                    this.oDetailSubBrowser = value;
                    this.oDetailSubBrowser.AutoGenerateColumns = false;
                }
            }
        }

        [Description("Difference <price x qty> and <amount>."), Category("Editor properties"), Browsable(false), DefaultValue(0)]
        public decimal DiffAmountRange
        {
            get
            {
                if (string.IsNullOrEmpty(this.TranCurrencyCode) || (this.TranCurrencyCode == AppInstance.DefaultCurrency))
                {
                    return AppInstance.AmountRange;
                }
                if (this.ExchangeType)
                {
                    return decimal.Round(AppInstance.AmountRange / this.ExchangeRate, this.FCAmountDecimals);
                }
                return decimal.Round(AppInstance.AmountRange * this.ExchangeRate, this.FCAmountDecimals);
            }
        }

        [Browsable(false), Description("Difference <amount x %discount> and <discount amount>."), DefaultValue(0), Category("Editor properties")]
        public decimal DiffDiscountRange
        {
            get
            {
                if (!string.IsNullOrEmpty(this.TranCurrencyCode) && !(this.TranCurrencyCode == AppInstance.DefaultCurrency))
                {
                    return decimal.Round(AppInstance.DiscountRange / this.ExchangeRate, this.FCAmountDecimals);
                }
                return AppInstance.DiscountRange;
            }
        }

        [Category("Editor properties"), Browsable(false), Description("Difference <amount x VAT rate> and <VAT amount>."), DefaultValue(0)]
        public decimal DiffVATRange
        {
            get
            {
                if (!string.IsNullOrEmpty(this.TranCurrencyCode) && !(this.TranCurrencyCode == AppInstance.DefaultCurrency))
                {
                    return decimal.Round(AppInstance.VATRange / this.ExchangeRate, this.FCAmountDecimals);
                }
                return AppInstance.VATRange;
            }
        }

        [Description("The number of digits after decimal symbol (Exchange rate format)."), DefaultValue(0), Browsable(false), Category("Editor properties")]
        public int ExchangeDecimals
        {
            get
            {
                return AppInstance.ExchangeFormat;
            }
        }

        [DefaultValue(0), Description("The exchange rate of the current currency. This to calculate the invoice amount."), Category("Editor properties"), Browsable(false)]
        public decimal ExchangeRate
        {
            get
            {
                if (this.ExchangeType)
                {
                    return this.ExchangeRateOfBook;
                }
                return (1M / this.ExchangeRateOfBook);
            }
        }

        [Category("Editor properties"), Description("The exchange rate of the current currency. This to write to the invoice."), DefaultValue(1), Browsable(false)]
        public decimal ExchangeRateOfBook
        {
            get
            {
                return this.ii_ExchangeRateOfBook;
            }
            set
            {
                this.ii_ExchangeRateOfBook = value;
            }
        }

        [Category("Editor properties"), Description("The exchange type of the current currency. This to write to the invoice."), Browsable(false), DefaultValue(0)]
        public bool ExchangeType
        {
            get
            {
                return this.ib_ExchangeType;
            }
            set
            {
                this.ib_ExchangeType = value;
            }
        }

        [Browsable(false), DefaultValue((string) null), Category("Editor properties"), Description("The parameters that declare by system, user, invoice code.")]
        public AppInvoiceLib AppInvoiceParameters
        {
            get
            {
                if (this.oAppInvoiceLib == null)
                {
                    this.AppInvoiceParameters = new AppInvoiceLib();
                }
                return this.oAppInvoiceLib;
            }
            set
            {
                this.oAppInvoiceLib = value;
            }
        }

        [Category("Editor properties"), Browsable(false), Description("The parameters that declare by system, user, invoice code."), DefaultValue((string) null)]
        public AppPrintInvoiceLib AppPrintLib
        {
            get
            {
                if (this.oAppPrintLib == null)
                {
                    this.oAppPrintLib = new AppPrintInvoiceLib();
                }
                return this.oAppPrintLib;
            }
            set
            {
                this.oAppPrintLib = value;
            }
        }

        [Category("Editor properties"), Description("The number of digits after decimal symbol (Foreign currency amount)."), DefaultValue(0), Browsable(false)]
        public int FCAmountDecimals
        {
            get
            {
                if (!string.IsNullOrEmpty(this.TranCurrencyCode) && !(this.TranCurrencyCode == AppInstance.DefaultCurrency))
                {
                    return AppInstance.FCAmountDecimals;
                }
                return AppInstance.LCAmountDecimals;
            }
        }

        [Category("Editor properties"), Description("The number of digits after decimal symbol (Foreign currency price)."), DefaultValue(0), Browsable(false)]
        public int FCPriceDecimals
        {
            get
            {
                if (!string.IsNullOrEmpty(this.TranCurrencyCode) && !(this.TranCurrencyCode == AppInstance.DefaultCurrency))
                {
                    return AppInstance.FCPriceDecimals;
                }
                return AppInstance.LCPriceDecimals;
            }
        }

        [Browsable(false)]
        public TextSearch InputTypeTextBox
        {
            get
            {
                return this.oInputTypeTextBox;
            }
            set
            {
                this.oInputTypeTextBox = value;
                if (!string.IsNullOrEmpty(this.InvoiceCode))
                {
                    if (string.IsNullOrEmpty(this.oInputTypeTextBox.FirstFilter))
                    {
                        this.oInputTypeTextBox.FirstFilter = "Ct_Nx LIKE '%" + this.InvoiceCode + "%'";
                    }
                    else
                    {
                        this.oInputTypeTextBox.FirstFilter = this.oInputTypeTextBox.FirstFilter + " AND Ct_Nx LIKE '%" + this.InvoiceCode + "%'";
                    }
                }
            }
        }

        [Category("Editor properties"), DefaultValue(""), Browsable(false), Description("The current invoice code to edit or add.")]
        public string InvoiceCode
        {
            get
            {
                if (this.AppInvoiceParameters == null)
                {
                    return "";
                }
                return this.AppInvoiceParameters.InvoiceCode;
            }
            set
            {
                if (this.AppInvoiceParameters != null)
                {
                    this.AppInvoiceParameters.InvoiceCode = value;
                    if (!string.IsNullOrEmpty(this.AppInvoiceParameters.InvoiceCode) && AppDataAccess.CheckConnected)
                    {
                        this.Text = this.AppInvoiceParameters.InvoiceName;
                        this.OnResetControls();
                    }
                }
            }
        }

        [Category("Editor properties"), Description("The number of digits after decimal symbol (Local currency amount)."), DefaultValue(0), Browsable(false)]
        public int LCAmountDecimals
        {
            get
            {
                return AppInstance.LCAmountDecimals;
            }
        }

        [Category("Editor properties"), Description("The number of digits after decimal symbol (Local currency price)."), DefaultValue(0), Browsable(false)]
        public int LCPriceDecimals
        {
            get
            {
                return AppInstance.LCPriceDecimals;
            }
        }

        [Description("The detail dataset."), DefaultValue((string) null), Browsable(false), Category("Editor properties")]
        public DataSet LocalDetailDataSet
        {
            get
            {
                return this.oLocalDetailDataSet;
            }
            set
            {
                this.oLocalDetailDataSet = value;
            }
        }

        [Category("Editor properties"), Description("The detail row."), DefaultValue((string) null), Browsable(false)]
        public DataRow LocalDetailRow
        {
            get
            {
                if (((this.DetailGridBrowser != null) && (this.DetailGridBrowser.CurrentRow != null)) && (this.DetailGridBrowser.CurrentRow.DataBoundItem != null))
                {
                    return ((DataRowView) this.DetailGridBrowser.CurrentRow.DataBoundItem).Row;
                }
                return this.oLocalDetailRow;
            }
            set
            {
                this.oLocalDetailRow = value;
            }
        }

        [DefaultValue((string) null), Description("The detail Table."), Category("Editor properties"), Browsable(false)]
        public DataTable LocalDetailTable
        {
            get
            {
                return this.LocalDetailDataSet.Tables[0];
            }
        }

        [Category("Editor properties"), Browsable(false), Description("The lister form."), DefaultValue((string) null)]
        public FormLister LocalFormLister
        {
            get
            {
                return this.oLocalFormLister;
            }
            set
            {
                this.oLocalFormLister = value;
            }
        }

        [Browsable(false), DefaultValue((string) null), Category("Editor properties"), Description("The master row.")]
        public DataRow LocalMasterRow
        {
            get
            {
                return this.oLocalMasterRow;
            }
            set
            {
                this.oLocalMasterRow = value;
            }
        }

        [Category("Editor properties"), DefaultValue((string) null), Browsable(false), Description("The parent master datarow.")]
        public DataRow LocalParentMasterRow
        {
            get
            {
                return this.oLocalParentMasterRow;
            }
            set
            {
                this.oLocalParentMasterRow = value;
            }
        }

        [DefaultValue("Stt"), Category("Editor properties"), Description("The master primary key field name.")]
        public string MasterKeyField
        {
            get
            {
                if (this.AppInvoiceParameters == null)
                {
                    return "";
                }
                return this.AppInvoiceParameters.MasterKeyField;
            }
            set
            {
                if (this.AppInvoiceParameters != null)
                {
                    this.AppInvoiceParameters.MasterKeyField = value;
                }
            }
        }

        [Description("Indicate that we are on the master grid or detail grid."), DefaultValue(true), Browsable(false), Category("Editor properties")]
        public bool MasterOrDetail
        {
            get
            {
                return this.ib_MasterOrDetail;
            }
            set
            {
                if (this.ib_MasterOrDetail != value)
                {
                    this.ib_MasterOrDetail = value;
                }
            }
        }

        [Description("The number of digits after decimal symbol (Quantity)."), Category("Editor properties"), Browsable(false), DefaultValue(0)]
        public int QuantityDecimals
        {
            get
            {
                return AppInstance.QuantityDecimals;
            }
        }

        [Description("The last detail invoice order."), Category("Editor properties"), Browsable(false), DefaultValue("")]
        public string SavedDetailOrder
        {
            get
            {
                return this.is_SavedDetailOrder;
            }
            set
            {
                bool flag = this.is_SavedDetailOrder == value;
                this.is_SavedDetailOrder = value;
                if ((this.MasterOrDetail && flag) || !flag)
                {
                    this.OnShowDetailNotice();
                }
                if (!flag)
                {
                    this.OnShowDetail();
                }
            }
        }

        [Description("The last master invoice order."), DefaultValue(""), Browsable(false), Category("Editor properties")]
        public string SavedMasterOrder
        {
            get
            {
                return this.is_SavedMasterOrder;
            }
            set
            {
                if (this.is_SavedMasterOrder != value)
                {
                    this.is_SavedMasterOrder = value;
                }
            }
        }

        [Browsable(false), Category("Editor properties"), Description("Functions.")]
        public ToolStripItem[] ToolStripFunctions
        {
            set
            {
                if (value != null)
                {
                    this.btnFunctions.DropDownItems.AddRange(value);
                }
                else
                {
                    this.btnFunctions.Visible = false;
                    this.tbrSep01.Visible = false;
                }
            }
        }

        [Category("Editor properties"), Browsable(false), Description("The transaction currency code of current invoice."), DefaultValue("")]
        public string TranCurrencyCode
        {
            get
            {
                return this.is_TranCurrencyCode;
            }
            set
            {
                if (this.is_TranCurrencyCode != value)
                {
                    this.is_TranCurrencyCode = value;
                    if (string.IsNullOrEmpty(this.TranCurrencyCode) || (AppInstance.DefaultCurrency == this.is_TranCurrencyCode))
                    {
                        this.ExchangeRateOfBook = 1M;
                        this.ExchangeType = true;
                    }
                    else
                    {
                        bool flag = true;
                        decimal num = this.AppInvoiceParameters.AppInvoiceMethod.ExchangeRate(this.TranCurrencyCode, ref flag);
                        this.ExchangeType = flag;
                        this.ExchangeRateOfBook = num;
                    }
                }
            }
        }

        [Browsable(false), Category("Editor properties"), Description("The warning message.")]
        public string WarningMessage
        {
            set
            {
                this.lblNotice.Text = value;
            }
        }
    }
}

